﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace KeZhou.Views.Components.Customs
{
    /// <summary>
    /// Message.xaml 的交互逻辑
    /// </summary>
    public partial class Message : ContentControl
    {
        public delegate void CloseButtonClickedHandler(Message m);
        public event CloseButtonClickedHandler CloseButtonClicked;

        // 用于触发动画
        public event EventHandler Removed;

        public bool hasRemoved = false;

        public Message(string title, string content)
        {
            InitializeComponent();
            Title.Text = title;
            Content.Text = content;
        }

        private void PackIconEvaIcons_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            OnRemoved();
            // 先触发动画再从MessageHost中移除
            var timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(2);
            timer.Tick += (sender, e) =>
            {
                CloseButtonClicked(this);
                timer.Stop();
            };
            timer.Start();
        }

        public void OnRemoved()
        {
            hasRemoved = true;
            Removed?.Invoke(this, EventArgs.Empty);
        }
    }
}
